package com.ruoyi.project.device.warehouse.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.device.warehouse.domain.BasWarehouse;
import com.ruoyi.project.device.warehouse.service.IBasWarehouseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库管理Controller
 * 
 * @author wld
 * @date 2023-04-04
 */
@Controller
@RequestMapping("/device/warehouse")
public class BasWarehouseController extends BaseController
{
    private String prefix = "device/warehouse";

    @Autowired
    private IBasWarehouseService basWarehouseService;

    @GetMapping()
    public String warehouse()
    {
        return prefix + "/warehouse";
    }

    /**
     * 查询仓库管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasWarehouse basWarehouse)
    {
        startPage();
        List<BasWarehouse> list = basWarehouseService.selectBasWarehouseList(basWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出仓库管理列表
     */
    @Log(title = "仓库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasWarehouse basWarehouse)
    {
        List<BasWarehouse> list = basWarehouseService.selectBasWarehouseList(basWarehouse);
        ExcelUtil<BasWarehouse> util = new ExcelUtil<BasWarehouse>(BasWarehouse.class);
        return util.exportExcel(list, "仓库管理数据");
    }

    /**
     * 新增仓库管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存仓库管理
     */
    @Log(title = "仓库管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasWarehouse basWarehouse)
    {
        return toAjax(basWarehouseService.insertBasWarehouse(basWarehouse));
    }

    /**
     * 修改仓库管理
     */
    @GetMapping("/edit/{warehouseId}")
    public String edit(@PathVariable("warehouseId") String warehouseId, ModelMap mmap)
    {
        BasWarehouse basWarehouse = basWarehouseService.selectBasWarehouseByWarehouseId(warehouseId);
        mmap.put("basWarehouse", basWarehouse);
        return prefix + "/edit";
    }

    /**
     * 修改保存仓库管理
     */
    @Log(title = "仓库管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasWarehouse basWarehouse)
    {
        return toAjax(basWarehouseService.updateBasWarehouse(basWarehouse));
    }

    /**
     * 删除仓库管理
     */
    @Log(title = "仓库管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basWarehouseService.deleteBasWarehouseByWarehouseIds(ids));
    }
}
